///*
// * Copyright (c) 2020 hebeiyiliuba.com
// * All rights reserved.
// *
// */
//package org.jeecg.modules.middleware.quartz.job.tosupload;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import org.apache.commons.collections4.CollectionUtils;
//import org.jeecg.modules.third.tosapi.dto.TosApiBaseResDTO;
//import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
//import org.jeecg.modules.wlhy.bill.service.IHyShippingNoteBillService;
//import org.jeecg.modules.wlhy.report.ShippingNoteTosApiService;
//import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
//import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * 快货运--上报脚本
// *
// * @author duanlikao
// * @created 2021/07/22
// */
//@Service
//public class TosUploadJobService {
//    private static final Logger LOGGER = LoggerFactory.getLogger(TosUploadJobService.class);
//
//    @Autowired
//    private IHyShippingNoteService shippingNoteService;
//    @Autowired
//    private IHyShippingNoteBillService hyShippingNoteBillService;
//
//    @Autowired
//    private ShippingNoteTosApiService shippingNoteTosApiService;
//
//    public SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//    /**
//     * 已接单运单同步合同
//     */
//    //@Scheduled(cron = "0 0/30 * * * ?") //半小时执行一次
//    public  void  tosUploadWaybillContract(){
//      Long start = System.currentTimeMillis();
//      LOGGER.info("UploadJobService tosUploadWaybillContract:执行运单同步合同数据开始" + now.format(new Date()));
//      QueryWrapper<HyShippingNote> queryWrapper = new QueryWrapper();
//
//      queryWrapper.eq("shipping_status","1");
//      queryWrapper.eq("tos_identification","1");
//      queryWrapper.orderByDesc("status_dt_receive");
//
//        Page <HyShippingNote> page = new Page<>(1, 100);
//        IPage <HyShippingNote> pageList = shippingNoteService.page(page, queryWrapper);
//        List<HyShippingNote>    shippingNotes = pageList.getRecords();
//      if(CollectionUtils.isNotEmpty(shippingNotes)){
//          for(HyShippingNote hyShippingNote:shippingNotes){
//              try {
//                  shippingNoteTosApiService.waybillCustomerContract( hyShippingNote);
//                  shippingNoteTosApiService.waybillContract(hyShippingNote);
//              }catch (Exception e){
//                  LOGGER.info("UploadJobService tosUploadWaybillContract:Exception : {}" ,e.getMessage());
//                  continue;
//              }
//          }
//      }
//      LOGGER.info("UploadJobService tosUploadWaybillContract:执行运单同步合同数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//
//    /**
//     * 签收运单同步运单轨迹
//     */
//    //@Scheduled(cron = "0 0/30 * * * ?") //半小时执行一次
//    public  void  tosUploadWaybillGeo(){
//        Long start = System.currentTimeMillis();
//        LOGGER.info("UploadJobService tosUploadWaybillGeo:执行同步运单轨迹数据开始" + now.format(new Date()));
//        QueryWrapper<HyShippingNote> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("shipping_status","5");
//        queryWrapper.eq("tos_identification","1");
//        queryWrapper.orderByDesc("status_dt_sign");
//
//        Page <HyShippingNote> page = new Page<>(1, 100);
//        IPage <HyShippingNote> pageList = shippingNoteService.page(page, queryWrapper);
//        List<HyShippingNote>    shippingNotes = pageList.getRecords();
//        if(CollectionUtils.isNotEmpty(shippingNotes)){
//            for(HyShippingNote hyShippingNote:shippingNotes){
//                try {
//                    shippingNoteTosApiService.waybillGeo(hyShippingNote);
//                }catch (Exception e){
//                    LOGGER.info("UploadJobService tosUploadWaybillGeo:Exception : {}" ,e.getMessage());
//                    continue;
//                }
//            }
//        }
//        LOGGER.info("UploadJobService tosUploadWaybillGeo:执行同步运单轨迹数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//    /**
//     * 已支付同步更新运单和上传资金流水
//     */
//    //@Scheduled(cron = "0 0 0/1 * * ?") //每小时执行一次
//    public  void  tosUpWaybill(){
//        Long start = System.currentTimeMillis();
//        LOGGER.info("UploadJobService tosUpWaybill:执行同步运单数据开始" + now.format(new Date()));
//        QueryWrapper<HyShippingNote> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("shipping_pay_status","6");
//        queryWrapper.eq("tos_identification","1");
//        queryWrapper.orderByDesc("pay_dt");
//
//        Page <HyShippingNote> page = new Page<>(1, 500);
//        IPage <HyShippingNote> pageList = shippingNoteService.page(page, queryWrapper);
//        List<HyShippingNote>    shippingNotes = pageList.getRecords();
//        if(CollectionUtils.isNotEmpty(shippingNotes)){
//            for(HyShippingNote hyShippingNote:shippingNotes){
//                try {
//                    TosApiBaseResDTO tosApiBaseResDTO =  shippingNoteTosApiService.waybillCreate(hyShippingNote);
//                    if(tosApiBaseResDTO.isSuccess() ){ //上传资金流水信息
//                        shippingNoteTosApiService.waybillPayment(hyShippingNote);
//                    }
//                }catch (Exception e){
//                    LOGGER.info("UploadJobService tosUpWaybill:Exception : {}" ,e.getMessage());
//                    continue;
//                }
//            }
//        }
//        LOGGER.info("UploadJobService tosUpWaybill:执行同步运单数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//
//    /**
//     * 快货运--运单确认接口
//     */
//    //@Scheduled(cron = "0 0 0/2 * * ?") //每2小时执行一次
//    public  void  tosWaybillConfirm(){
//        Long start = System.currentTimeMillis();
//        LOGGER.info("UploadJobService tosWaybillConfirm:执行同步运单确认数据开始" + now.format(new Date()));
//        QueryWrapper<HyShippingNoteBill> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("tos_shippingnote_able","0");
//        queryWrapper.eq("tos_identification","1");
//        queryWrapper.orderByDesc("create_time");
//
//        Page <HyShippingNoteBill> page = new Page<>(1, 200);
//        IPage <HyShippingNoteBill> pageList = hyShippingNoteBillService.page(page, queryWrapper);
//        List<HyShippingNoteBill>    shippingNoteBills = pageList.getRecords();
//        if(CollectionUtils.isNotEmpty(shippingNoteBills)){
//            try {
//                List<String> shippingNoteNumbers = shippingNoteBills.stream().map(HyShippingNoteBill::getShippingNoteNumber).collect(Collectors.toList());
//                shippingNoteTosApiService.waybillConfirm(shippingNoteNumbers);
//            }catch (Exception e){
//                LOGGER.info("UploadJobService tosWaybillConfirm:Exception : {}" ,e.getMessage());
//            }
//        }
//        LOGGER.info("UploadJobService tosWaybillConfirm:执行同步运单确认数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//
//    /**
//     *  快货运--运单自检结果查询接口
//     */
//    //@Scheduled(cron = "0 0 0/3 * * ?") //每3小时执行一次
//    public  void  tosInvoiceWaybillCheck(){
//        Long start = System.currentTimeMillis();
//        LOGGER.info("UploadJobService tosInvoiceWaybillCheck:执行同步运单自检数据开始" + now.format(new Date()));
//        QueryWrapper<HyShippingNoteBill> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("tos_shippingnote_able","0");
//        queryWrapper.eq("tos_identification","1");
//        queryWrapper.orderByDesc("create_time");
//
//        Page <HyShippingNoteBill> page = new Page<>(1, 500);
//        IPage <HyShippingNoteBill> pageList = hyShippingNoteBillService.page(page, queryWrapper);
//        List<HyShippingNoteBill>    shippingNoteBills = pageList.getRecords();
//        if(CollectionUtils.isNotEmpty(shippingNoteBills)){
//            try {
//                List<String> shippingNoteNumbers = shippingNoteBills.stream().map(HyShippingNoteBill::getShippingNoteNumber).collect(Collectors.toList());
//                shippingNoteTosApiService.invoiceWaybillCheck(shippingNoteNumbers);
//            }catch (Exception e){
//                LOGGER.info("UploadJobService tosInvoiceWaybillCheck:Exception : {}" ,e.getMessage());
//            }
//        }
//        LOGGER.info("UploadJobService tosInvoiceWaybillCheck:执行同步运单自检数据结束,耗时:"+(System.currentTimeMillis()-start)+"毫秒----");
//
//    }
//
//
//
//}
